package com.cskaoyan.exception;

import com.cskaoyan.module.bean.BaseRespVo;
import org.springframework.boot.json.JsonParseException;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;

/**
 * Created with IntelliJ IDEA.
 *
 * @Description:
 * @Author: 周佳豪
 * @Date: 2022/04/08/20:33
 */
@ControllerAdvice
public class Exceptions {
    @ExceptionHandler(HttpMessageNotReadableException.class)
    @ResponseBody
    public BaseRespVo exceptionHandler(HttpMessageNotReadableException e){
        e.printStackTrace();
        BaseRespVo<Object> baseRespVo1 = new BaseRespVo<>();
        baseRespVo1.setErrno(402);
        baseRespVo1.setErrmsg("参数值不对");
        return baseRespVo1;
    }
    @ExceptionHandler(MethodArgumentTypeMismatchException.class)
    @ResponseBody
    public BaseRespVo exceptionHandler2(MethodArgumentTypeMismatchException e){
        BaseRespVo<Object> baseRespVo1 = new BaseRespVo<>();
        baseRespVo1.setErrno(402);
        baseRespVo1.setErrmsg("参数值不对");
        return baseRespVo1;
    }
}
